package hz.mobileproject.pda.ui.adapter;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.SPUtils;

import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.firesafety.bean.Response_queryfire;

/**
 * Created by zmybi on 2017/12/7.
 */

public class FireListRecyclerViewAdapter extends RecyclerView.Adapter<FireListRecyclerViewAdapter.MyViewHolder> {

    private final List<Response_queryfire> response_queryfireList;
    private SPUtils spUtils;

    public FireListRecyclerViewAdapter(List<Response_queryfire> response_queryfireList) {
        this.response_queryfireList = response_queryfireList;
        spUtils = SPUtils.getInstance("app_login");
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(
                parent.getContext()).inflate(R.layout.fire_list_item, parent,
                false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        //数据和视图绑定
        Response_queryfire queryfire = response_queryfireList.get(position);
        holder.tv_box_name.setText(queryfire.box_name);
        holder.tv_asset_code.setText(queryfire.asset_code);
        holder.tv_code.setText(queryfire.code);
        holder.tv_name.setText(queryfire.name);
        holder.tv_purchase_date.setText(queryfire.purchase_date);
        holder.tv_produce_date.setText(queryfire.produce_date);
        holder.tv_expired_date.setText(queryfire.expired_date);
        holder.tv_change_date.setText(queryfire.change_date);

        if(queryfire.isSaveClick) {
            holder.tv_asset_code.setTextColor(Color.RED);
            holder.ll_back_to_xianshi.setVisibility(View.VISIBLE);
            holder.tv_is_guoqi.setText(queryfire.isGuoQi);
            holder.tv_zichan_zhuangkuang.setText(queryfire.ziChan);
            holder.et_shuoming.setText(queryfire.shuoMing);
        }else {
            holder.tv_asset_code.setTextColor(Color.BLACK);
            holder.ll_back_to_xianshi.setVisibility(View.GONE);
        }

    }

    @Override
    public int getItemCount() {
        return response_queryfireList == null ? 0 : response_queryfireList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{

        public TextView tv_box_name;
        public TextView  tv_asset_code;
        public TextView  tv_code;
        public TextView  tv_name;
        public TextView tv_purchase_date;
        public TextView tv_produce_date;
        public TextView tv_expired_date;
        public TextView tv_change_date;

        //扫码返回更新
        public LinearLayout ll_back_to_xianshi;
        public TextView tv_is_guoqi;
        public TextView tv_zichan_zhuangkuang;
        public TextView et_shuoming;

        public MyViewHolder(View itemView) {
            super(itemView);
            tv_box_name = (TextView) itemView.findViewById(R.id.tv_box_name);
            tv_asset_code = (TextView) itemView.findViewById(R.id.tv_asset_code);
            tv_code = (TextView) itemView.findViewById(R.id.tv_code);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_purchase_date = (TextView) itemView.findViewById(R.id.tv_purchase_date);
            tv_produce_date = (TextView) itemView.findViewById(R.id.tv_produce_date);
            tv_expired_date = (TextView) itemView.findViewById(R.id.tv_expired_date);
            tv_change_date = (TextView) itemView.findViewById(R.id.tv_change_date);

            ll_back_to_xianshi = (LinearLayout) itemView.findViewById(R.id.ll_back_to_xianshi);
            tv_is_guoqi = (TextView) itemView.findViewById(R.id.tv_is_guoqi);
            tv_zichan_zhuangkuang = (TextView) itemView.findViewById(R.id.tv_zichan_zhuangkuang);
            et_shuoming = (TextView) itemView.findViewById(R.id.et_shuoming);

        }
    }
}
